<?php

/*
*后台用户接口api
*/
  /** * * ━━━━━━神兽出没━━━━━━
   * 　　　┏┓　　　┏┓
   * 　　┏┛┻━━━┛┻┓
   * 　　┃　　　　　　　┃
   * 　　┃　　　━　　　┃
   * 　　┃　┳┛　┗┳　┃
   * 　　┃　　　　　　　┃
   * 　　┃　　　┻　　　┃
   * 　　┃　　　　　　　┃
   * 　　┗━┓　　　┏━┛
   * 　　　　┃　　　┃       Code is far away from bug with the animal protecting
   * 　　　　┃　　　┃         神兽保佑,代码无bug
   * 　　　　┃　　　┗━━━┓
   * 　　　　┃　　　　　　　┣┓
   * 　　　　┃　　　　　　　┏┛
   * 　　　　┗┓┓┏━┳┓┏┛
   * 　　　　　┃┫┫　┃┫┫
   * 　　　　　┗┻┛　┗┻┛
   *  ━━━━━━感觉萌萌哒━━━━━━
   */

namespace app\system\controller;
use think\Controller;
use think\Request; 
use \think\Db;
class User extends \app\api\controller\Base
{
  protected static $tb = [
      'area'    => 'area', 
  ]; 
   /*
   * 经销商列表
   */
	public function shop_list(){
      $data =$this->data;  
      $check = $this->validate($data,'User.shop');
      if($check !==true){
        return api_return($check);
      }
      $result = model("User")->getShopList($data);
      return api_return(10002,$result); 
	}

   /*
   * 经销商详情
   */
   public function shop_detail(){
        $data =$this->data;
        $check = $this->validate($data,'User.shop_detail');
        if($check !==true){
          return api_return($check);
        }
        $result = model("User")->getShopDetail($data);
        if($result !== false && $result >0){
          return api_return(10002,$result);
        }else{
           return api_return(-10023);
        }
   }

  /*
   * 经销商审核
   */
   public function shop_commit(){
     $data =$this->data;
     $check = $this->validate($data,'User.shop_commit');
     if($check !==true){
       return api_return($check);
     }
     $result = model("User")->commitShop($data);
     if($result !== false && $result >0){
       return api_return(10008,$result);
     }else{
        return api_return($result);
     }
   }

  /*
   * 经销商删除
   */
   public function delete_shop(){
     $data =$this->data;
     $check = $this->validate($data,'User.shop_detail');
     if($check !==true){
       return api_return($check);
     }
     $result = model("User")->deleteShop($data);
     if($result !== false && $result >0){
       return api_return(10008,$result);
     }else{
        return api_return($result);
     }
   }
   

   /*
   * 业务经理列表
   */
	public function manager_list(){
     $data =$this->data;
     $check = $this->validate($data,'User.manager_list');
     if($check !==true){
       return api_return($check);
     }
     $result = model("User")->getManagerList($data);
     if($result !== false && $result >0){
       return api_return(10008,$result);
     }else{
        return api_return($result);
     }
	}

  /*
   * 业务经理详情
   */
   public function manager_detail(){
     $data = $this->data;
     $check = $this->validate($data,'User.manager_detail');
     if($check !==true){
       return api_return($check);
     }
     $result = model("User")->getManagerDetail($data);
     if($result !== false && $result >0){
       return api_return(10008,$result);
     }else{
        return api_return($result);
     }
   }

   /*
   * 业务经理审核
   */
   public function manager_commit(){
     $data =$this->data;
     $check = $this->validate($data,'User.manager_commit');
     if($check !==true){
       return api_return($check);
     }
     $result = model("User")->commitManager($data);
     if($result !== false && $result >0){
       return api_return(10008,$result);
     }else{
        return api_return($result);
     }
   }

  /*
   * 业务经理删除
   */
   public function manager_delete(){
     $data =$this->data;
     $check = $this->validate($data,'User.manager_detail');
     if($check !==true){
       return api_return($check);
     }
     $result = model("User")->managerDelete($data);
     if($result !== false && $result >0){
       return api_return(10008,$result);
     }else{
        return api_return($result);
     } 
   }


   /*
   * 业务员列表
   */
  public function sale_list(){
     $data =$this->data;
     $check = $this->validate($data,'User.sale_list');
     if($check !==true){
       return api_return($check);
     }
     $result = model("User")->getSaleList($data);
     if($result !== false && $result >0){
       return api_return(10002,$result);
     }else{
        return api_return($result);
     }
  }


  /*
   * 业务员详情
   */
  public function sale_detail(){
     $data =$this->data;
     $check = $this->validate($data,'User.manager_detail');
     if($check !==true){
       return api_return($check);
     }
     $result = model("User")->getSaleDetail($data);
     if($result !== false && $result >0){
       return api_return(10002,$result);
     }else{
        return api_return($result);
     }
  }
  
   /*
   * 业务员审核
   */
  public function sale_commit(){
     $data =$this->data;
     $check = $this->validate($data,'User.manager_commit');
     if($check !==true){
       return api_return($check);
     }
     $result = model("User")->commitManager($data);
     if($result !== false && $result >0){
       return api_return(10008,$result);
     }else{
        return api_return($result);
     } 
  }

   /*
   * 业务员删除
   */
  public function sale_delete(){
    $data = $this->data;
    $check = $this->validate($data,'User.manager_detail');
     if($check !==true){
       return api_return($check);
     }
     $result = model("User")->managerDelete($data);
     if($result !== false && $result >0){
       return api_return(10008,$result);
     }else{
        return api_return($result);
     }
  }


 /**
   * 获取省份
   */
   public function getProvinceList(){
      $sql = "select areaid,areaname,rowid,parentrowid from jun_area where char_length(areaid)=3";
      $province_list = Db::query($sql); 
      return api_return(10002,$province_list); 
      
   }
  
  /**
   * 获取城市列表
   */
  public function getCityList(){
      $data = $this->data; 
      $where['parentrowid'] = $data['rowid'];
      $field = "areaid,areaname,rowid,parentrowid";
      $city_list = Db::name(self::$tb['area'])->where($where)->field($field)->select();
      return api_return(10001,$city_list);
  }
 
   /**
   * 上传图片
   */
  public function ajaxuploads(){
      $file = request()->file('file');
      if($file){
          $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
          if($info){
              $pic = '/uploads/'.$info->getSaveName();
          }
        $pattern = '/\\\\/'; 
        $arr = [
            'status' =>'1',
            'path' =>preg_replace($pattern,'/',$pic),
        ];
      }else{
        $arr = [
            'status' =>0,
            'path' =>"上传图片",
        ];  
      }
      echo json_encode($arr);
  }


  public function edit_member(){
    $data = $this->data;
    $result = model("User")->edit_member($data);
     if($result !== false && $result >0){
       return api_return(10001,$result);
     }else{
        return api_return($result);
     }
  }

   /*
   * 业务员列表
   */
  public function sale_flow_list(){
     $data =$this->data;
     $check = $this->validate($data,'User.sale_list');
     if($check !==true){
       return api_return($check);
     }
     $result = model("User")->saleFlowList($data);
     if($result !== false && $result >0){
       return api_return(10002,$result);
     }else{
        return api_return($result);
     }
  }

   /*
   * 设置分佣
   */
  public function sale_flow_set(){
     $data =$this->data; 
     $result = model("User")->saleFlowSet($data); 
     if($result !== false && $result >0){
       return api_return(10002,$result);
     }else{
        return api_return($result);
     }
  }


 

    
}